﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Controls;

namespace FasterWPF
{
    public static class IterHelpers
    {
        public static void ApplyLoop(int startingIndex, int count, Action<int> intAction)
        {
            Enumerable.Range(startingIndex, count).ToList<int>().ForEach(i =>
            {
                intAction(i);
            });
        }

        public static void ApplyLoop(int count, Action<int> intAction)
        {
            Enumerable.Range(0, count).ToList<int>().ForEach(i =>
            {
                intAction(i);
            });
        }

        public static ContentControl ApplyToChild<T>(this
ContentControl chain, Action<T> funcToCall)
        {
            if (funcToCall != null)
            {
                funcToCall(chain.GetContent<T>());
            }

            return chain;
        }

        public static T Apply<T>(this T chain, Action<T> actionToCall)
    where T : System.Windows.FrameworkElement
        {
            if (actionToCall != null)
            {
                actionToCall(chain);
            }
            return chain;
        }

    }
}
